package com.seirsoft.framework.payload;

import java.util.ArrayList;


public class PayloadRowCollection
{
	ArrayList<PayloadRow> m_innerList;

	public PayloadRowCollection()
	{
		m_innerList = new ArrayList<PayloadRow>();
	}
	
	public int getCount()
	{
		return this.m_innerList.size();
	}
	
	public PayloadRow get(int index)
	{
		return this.m_innerList.get(index);
	}
	
    public void addRow(PayloadRow row)
    {
    	this.m_innerList.add(row);
    }
	
	public void clear()
	{
		this.m_innerList.clear();
	}
	
    /**
     *  Factory class that keeps the parse method
     */
    public static class Factory {
        /**
         * static method to create the object
         * Precondition:  If this object is an element, the current or next start element starts this object and any intervening reader events are ignorable
         *                If this object is not an element, it is a complex type and the reader is at the event just after the outer start element
         * Postcondition: If this object is an element, the reader is positioned at its end element
         *                If this object is a complex type, the reader is positioned at the end element of its outer element
         */
        public static void parse(
            javax.xml.stream.XMLStreamReader reader,
            PayloadTable dataTable) throws java.lang.Exception {
        	
        	PayloadRowCollection object = dataTable.getRows();

            try {

            	
                while (!reader.isStartElement() && !reader.isEndElement())
                    reader.next();

            	// get Next Element: <r> or </rows>
                do{
                	reader.next();
                } while (!reader.isStartElement() && !reader.isEndElement());


                while (reader.isStartElement())
                {
            		if(reader.getLocalName().equals("r"))
            		{
            			object.m_innerList.add(PayloadRow.Factory.parse(reader, dataTable));
            		}
            		else
            		{
            			// </Unkown>
	                    do{
	                    	reader.next();
	                    } while (!reader.isStartElement() && !reader.isEndElement());
            		}

            		// get next Element: <r> or </rows>
            		do{
                    	reader.next();
                    } while (!reader.isStartElement() && !reader.isEndElement());
                }
            } catch (javax.xml.stream.XMLStreamException e) {
                throw new java.lang.Exception(e);
            }
        }
    } //end of factory class

}
